<?php
/*
 * Create by Sony K Wibisono,S.Si
 * e-mail : sony@sonywibisono.com.
 */
function category_link(){
global $db;
$sql="select * from _link_category";
$result=$db->query($sql);
echo "<div id=\"menu\">";
while($row=$db->fetch_array($result)){
 extract($row);
 
 echo "<div id=\"menu_$id\" class='category'><a href=\"#\" style=\"width:210px\">$manufacturer</a>";
 link_list($id);
 echo "</div>\r\n";
}
echo "</div>";
}
function category_event(){
global $db;
$sql="select * from manufacturers";
$result=$db->query($sql);
echo "<div id=\"menu_right\">
    <b>Category</b><ul>";
while($row=$db->fetch_array($result)){
 extract($row);
 
 echo "<li><a href=\"?mod=events&cat=$id\" >$manufacturer</a>";
 echo "</li>\r\n";
}
 echo "</ul></div>";
}
function category_channel(){
global $db;
$sql="select * from _channel_category";
$result=$db->query($sql);
echo "<div id=\"menu_right\">
    <b>Category</b><ul>";
while($row=$db->fetch_array($result)){
 extract($row);
 
 echo "<li><a href=\"?mod=channel&cat=$id\" >$manufacturer</a>";
 echo "</li>\r\n";
}
 echo "</ul></div>";
}
function category_news(){
global $db;
$sql="select * from manufacturers";
$result=$db->query($sql);
echo "<div id=\"menu\">
<b>Category</b>    
<ul>";
while($row=$db->fetch_array($result)){
 extract($row);
 
 echo "<li ><a href=\"?mod=posting&cat=$id\" >$manufacturer</a>";
 post_list($id);
 echo "</li>\r\n";
}
echo "</ul></div>"; 
}
function post_list($category){
    global $db;
    if (!empty($category)){
    $sql="select id,title,post_category 
    from _post_contents where post_category=$category";
    } else {
       $sql="select id,title,post_category 
    from _post_contents"; 
    }
    $result=$db->query($sql);
    
   echo "<p>";
   while($row=$db->fetch_array($result)){
    extract($row);
    $title=substr($title,0,30);
    //echo "<div id=\"menu_$id\" class='category'><a href=\"#\" style=\"width:210px\">$manufacturer</a>";
    echo "<a class=\"menu_right\" href=\"?mod=posting&action=detail&page_id=$id\" >$title</a>\r\n";
   }
   echo "</p>";
   
}
function link_list($category){
    global $db;
    $sql="select * from _link_links where link_category=$category";
    $result=$db->query($sql);
    
   echo "<div id=\"submenu_$category\"><ul>";
   while($row=$db->fetch_array($result)){
    extract($row);
 
    echo "<li><a href=\"$url_link\" target=\"$target\">$link_caption</a>
 </li>\r\n";
   }
   echo "</ul></div>";
   echo "<script>$(\"#submenu_$category\").show();
   $(\"#menu_$link_category\").click(
   function (){
      $(\"#submenu_$category\").toggle(\"slow\");\r\n
   });\r\n
   </script>";
}
function is_word_exist($word){
    global $db;
    $sql="select count(*) from keywords where word='$word'";
    $row=$db->fetch_row($sql);
    if (!empty($row[0])){
        return $row[0]>0;
    } else return FALSE;
}
function is_tag_exist ($word_id,$page_id){
    global $db;
    $sql="select count(*) from page_tags where word_id=$word_id and page_id=$page_id";
    $row=$db->fetch_row($sql);
    if (!empty($row[0])){
        return $row[0]>0;
    } else return FALSE;
}
function is_tag_exists ($words){
    global $db;
    $sql="select count(*) from page_tags where word_id in ($words)";
    //echo $sql;
    $row=$db->fetch_row($sql);
    if (!empty($row[0])){
        return $row[0]>0;
    } else return false;
}
function show_word($word_id){
    global $db;
    $sql="select word from keywords where id=$word_id";
    $row=$db->fetch_row($sql);
    return $row['word'];
}
function show_online_user(){
    global $db;
    $sql="select distinct a.user_id,b.username,b.fullname,a.on_line 
        from _user_logs a, _user_users b
        where a.user_id=b.id and a.on_line='1'";
    $result=$db->query($sql);
    echo "";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($on_line=='1') {
            $imageurl="images/ic_online.png";
        } else {
            $imageurl="images/ic_offline.png";
            
        }
        echo "<div class='userlist'><img class='icon_small' src='$imageurl' title=\"$fullname\"/>
        $username <a href=\"?mod=messenger&action=send&user_to=$user_id\"><img src='images/message.png' title='Send Message'/></a></div>";
    }
}
function get_word_id($word){
    global $db;
    $sql="select id from keywords where word='$word'";
   // echo $sql;
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        return $row['id'];
    } else return 0;
}
function show_menus($position,$class){
    global $db;
    if(empty($position))$position="header";
    $sql="select * from menus where position ='$position' and visible ='Y'";
    $result=$db->query($sql);
    if ($position=='toolbar'){
    echo "<a href=\"index.php\">Home</a> ";
    }
    while($row=$db->fetch_array($result)){
        extract($row);
        if (!empty($class)){
             echo "<a href=\"$url_link\" class=\"$class\">$caption</a>";
        } else {
             echo "<a href=\"$url_link\">$caption</a>";
        }
       
        
    }
}
function insert_link_category($category,$pid){
    global $db;
    $sql="insert into _link_category(caterogy_name,parent) values ('$category',$pid);";
    $db->query($sql);
    return mysql_insert_id();
}
function show_search_form_header(){
    global $file;
     
        echo "<div class=\"search_header\">
            <form id=\"searchForm\" action=\"#\" method=\"post\">
                <input type=\"hidden\" name=\"action\" value=\"search\"/>
            <table><tr><td><input type=\"text\" size=\"50\" name=\"q\" /></td>
            <td><input type=\"submit\" class=\"tombol\" value=\"Search\"/></td>
            </tr></table>
           </form></div>";
    
}
function insertmanufacturers($category,$pid){
    global $db;
    $sql="insert into manufacturers(caterogy_name,parent) values ('$category',$pid);";
    $db->query($sql);
    return mysql_insert_id();
}
function insert_channel_category($category,$pid){
    global $db;
    $sql="insert into _channel_category(caterogy_name,parent) values ('$category',$pid);";
    $db->query($sql);
    return mysql_insert_id();
}
function insert_channel($channelname,$description,$category,$image){
    global $db;
    $sql="insert into _channel_channels   
    values (null,'$channelnamename','$description',$category,'$image');";
    $db->query($sql);
    return mysql_insert_id();
}
function insert_links ($caption,$category,$url,$target){
    global $db;
    $sql="insert into _link_links   
    values (null,'$caption',$category,'$url','$target');";
    $db->query($sql);
    return mysql_insert_id();
}
function select_category($categoryid){
    global $db;
    $sql="select _id,category from q_categories order by category";
    $result=$db->query($sql);
    $html="<select name=\"category_id\" class='textbox'>
        <option value=\"0\">Root</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($_id==$categoryid){
            $html.="<option value=\"$_id\" selected>$category</option>\r\n";
        } else $html.= "<option value=\"$_id\" >$category</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
function get_menu_modules($menuid){
    global $db;
    $sql="select app_module_id from app_menu_modules where app_menu_id=$menuid";
    $result=$db->query($sql);
    $nrow=  mysql_num_rows($result);
    if ($nrow>0){
    while($row=$db->fetch_array($result)){
        $mods[]=$row['app_module_id'];
    }
    return implode(';',$mods);
    } else return "";
}
function modules_checkbox($modules){
    global $db;
    $sql="select id,title from app_modules order by module_name";
    $result=$db->query($sql);
    $html="";
    $mods=explode(";",$modules);
    while ($row=$db->fetch_array($result)){
        extract($row);
        if (in_array($id, $mods)){
            $html.="<input type=\"checkbox\" name=\"modules[]\" value=\"$id\" checked/>$title\r\n";
        } else $html.= "<input type=\"checkbox\"  name=\"modules[]\" value=\"$id\" >$title\r\n";
    }
    $html.= "\r\n";
    return $html;
}
function get_base_namefile($filepath){
    $flies=explode('\\', $filepath);
    $index=count($flies);
    return $flies[$index-1];
}
function select_parent($parent_id){
    global $db;
    $sql="select _id,title from q_threads where parent_thread=0";
    $result=$db->query($sql);
    $html= "<select name=\"parent_thread\" class=\"textbox\">
        <option value=\"0\">No Parent</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($_id==$parent_id){
            $html.= "<option value=\"$_id\" selected>$category</option>\r\n";
        } else $html.= "<option value=\"$_id\" >$category</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
function select_request_type($request_type_id){
    global $db;
    $sql="select * from request_types order by request_type";
    $result=$db->query($sql);
    $html= "<select name=\"request_type_id\" class=\"textbox\">
        <option value=\"0\">No Priority</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($id==$request_type_id){
            $html.= "<option value=\"$id\" selected>$request_type</option>\r\n";
        } else $html.= "<option value=\"$id\" >$request_type</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
function select_site_location($customerid,$location_id){
    global $db;
    if (empty($customerid)){
        $customerid=0;
    }
    $sql="select * from site_locations where customer_id=$customerid order by site_name";
    $result=$db->query($sql);
    $html= "<select name=\"location_id\" class=\"textbox\">
        <option value=\"0\">No Priority</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($id==$request_type_id){
            $html.= "<option value=\"$id\" selected>$site_name</option>\r\n";
        } else $html.= "<option value=\"$id\" >$site_name</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
function select_manufacturers($manid){
    global $db;
    $sql="select * from manufacturers order by manufacturer";
    $result=$db->query($sql);
    $html= "<select name=\"manufacturer_id\" class=\"textbox\">
        <option value=\"0\">Root</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($id==$unitid){
            $html.= "<option value=\"$id\" selected>$manufacturer</option>\r\n";
        } else $html.= "<option value=\"$id\" >$manufacturer</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
function select_ticket_types($typeid){
    global $db;
    $sql="select * from ticket_types order by ticket_type";
    $result=$db->query($sql);
    $html= "<select name=\"ticket_type_id\" class=\"textbox\">
        <option value=\"0\">Root</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($id==$typeid){
            $html.= "<option value=\"$id\" selected>$ticket_type</option>\r\n";
        } else $html.= "<option value=\"$id\" >$ticket_type</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
function select_roles($key,$roleid){
    global $db;
    $sql="select * from app_roles order by role_name";
    $result=$db->query($sql);
    $html= "<select name=\"$key\" class=\"textbox\">";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($id==$roleid){
            $html.= "<option value=\"$id\" selected>$role_name</option>\r\n";
        } else $html.= "<option value=\"$id\" >$role_name</option>\r\n";
    }
    $html.= "</select>\r\n";
    return $html;
}
 
function select_ticket_status($status_id){
    global $db;
    $sql="select id,status_name from ticket_status_types order by status_name";
    $result=$db->query($sql);
    $html="<select name=\"status_type_id\" class=\"textbox\">
        <option value=\"0\">Root</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        if ($id==$channel_id){
            $html.= "<option value=\"$id\" selected>$status_name </option>\r\n";
        } else $html.="<option value=\"$id\" >$status_name_name</option>\r\n";
    }
    $html.="</select>\r\n";
    return $html;
}
function select_media_file($key,$media,$type){
    global $db;
    if (!empty($type)){
    $sql="select * from _media_file 
    where filetype='$type'    
    order by filename";
    } else {
     $sql="select * from _media_file 
     order by filename";   
    }
    $result=$db->query($sql);
    $html="<select name=\"$key\" class=\"textbox\">
        <option value=\"\">No File</option>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        $pos=strpos($filename,".");
        $filename=substr($filename,0,$pos);
        if (!empty($type)){
            $html.="<option value=\"$id\" >$filename </option>\r\n";
        } else {
            $html.="<option value=\"$id\" >$filetype -> $filename </option>\r\n";
        }
        
    }
    $html.="</select>\r\n";
    return $html;
}
function select_event_status($status){
    $event_mode=array('open','cancel','close','live','past');
    echo "<select name=\"event_status\" class=\"textbox\">";
    for ($i=0;$i<count($event_mode);$i++){
        if ($event_mode[$i]==$status){
           echo "<option value=\"".$event_mode[$i]."\" selected>".$event_mode[$i]."</option>\r\n"; 
        } else
       echo "<option value=\"".$event_mode[$i]."\" >".$event_mode[$i]."</option>\r\n"; 
    }
    echo "</select>\r\n";
}
function select_login_type($key,$messenger){
    $mode=array('default','facebook','google','twitter');
    $html= "<select name=\"$key\" class=\"textbox\">";
    for ($i=0;$i<count($mode);$i++){
        if ($mode[$i]==$messenger){
           $html.= "<option value=\"".$mode[$i]."\" selected>".$mode[$i]."</option>\r\n"; 
        } else
       $html.= "<option value=\"".$mode[$i]."\" >".$mode[$i]."</option>\r\n"; 
    }
    $html.= "</select>\r\n";
    return $html;
}
function select_filetype($key,$filetype){
    $mode=array('video','pdf','docx','doc','ppt','pptx');
    $html= "<select name=\"$key\" class=\"textbox\">";
    for ($i=0;$i<count($mode);$i++){
        if ($mode[$i]==$filetype){
          $html.= "<option value=\"".$mode[$i]."\" selected>".$mode[$i]."</option>\r\n"; 
        } else
       $html.= "<option value=\"".$mode[$i]."\" >".$mode[$i]."</option>\r\n"; 
    }
    $html.="</select>\r\n";
    return $html;
}
function select_hour($key,$value){
     $html= "<select name=\"$key\" class=\"textbox\">";
    for ($i=0;$i<24;$i++){
       $waktu=substr("00", strlen($i))."$i"; 
        if (strcmp($waktu,$value)==0){
           $html.= "<option value=\"".$waktu."\" selected>".$waktu."</option>\r\n";  
        } else
       $html.= "<option value=\"".$waktu."\" >".$waktu."</option>\r\n"; 
    }
    $html.="</select>\r\n";
    return $html;
    
}
function select_minute($key,$value){
    $html= "<select name=\"$key\" class=\"textbox\">";
    for ($i=0;$i<60;$i++){
        $waktu=substr("00", strlen($i))."$i"; 
        if (strcmp($waktu,$value)==0){
           $html.= "<option value=\"".$waktu."\" selected>".$waktu."</option>\r\n";  
        } else
        $html.= "<option value=\"".$waktu."\" >".$waktu."</option>\r\n"; 
    }
    $html.="</select>\r\n";
    return $html;
    
}
function word_rised($word){
    global $db;
    $sql="update keywords set rise=rise+1 where word='$word';";
    $db->query($sql);
}
function show_tags (){
    global $db;
    $sql="select * from keywords where rise>0 
        and id in (select distinct word_id from page_tags)
        order by word asc";
    $result=$db->query($sql);
    echo "<div class=\"menu_right\">
        <h2>Tag</h2>";
    while ($row=$db->fetch_array($result)){
        extract($row);
        $ukuran=$rise%5;
        echo "<a class=\"tag\" href=\"index.php?mod=posting&action=tag&word_id=$id\" 
        title=\"$rise permintaan\"><font size=\"+$ukuran\">$word</font></a>  ";
    }
    echo "</div>";
}
function show_keyword (){
    global $db;
    $sql="select * from keywords where rise>0 order by word asc";
    $result=$db->query($sql);
    $html="";
    while ($row=$db->fetch_array($result)){
        extract($row);
        echo "$word "; 
        
    }
   // return $html;
}
function insert_word($word){
    global $db;
    $sql="insert into keywords values (null,'$word')";
    $db->query($sql);
    return mysql_insert_id();
}
function insert_tagged($taged){
    global $db;
    $words=explode(" ", $taged);
    for ($i=0;$i<count($words);$i++){
      //  echo $words[$i].",";
     if (is_word_exist($words[$i])){
     $word_id[$i]=get_word_id($words[$i]);
     } else {
     $word_id[$i]=insert_word($words[$i]);
     }
       // echo $word_id[$i].":";
    word_rised($words[$i]);
     
    } 
    if (is_array($word_id)){
        $wordes=implode(",", $word_id);
    }
    return $wordes;
}

function insert_event_subscriber($eventid,$userid,$institution,$viconip,$other){
    global $db;
    $sql="insert into _event_subscriber values 
    ($eventid,$userid,'0','0','0','$institution','$viconip','$other')";
    $db->query($sql);
    return mysql_insert_id();
}
function is_user_exist($username){
    global $db;
    $sql="select count(*) from users where username='$username'";
    $row=$db->fetch_row($sql);
    if (!empty($row[0])){
       // echo "jumlah user".$row[0];
        return $row[0]>0;
    } else return false;
}
function get_user_info($username,$field){
    global $db;
    $sql="select $field from users where username='$username'";
    $row=$db->fetch_row($sql);
    return $row[$field];
}
function get_manufacturer($id){
    global $db;
    $sql="select manufacturer from manufacturers where id=$id";
    $row=$db->fetch_row($sql);
    return $row[0];
}


function get_user_info_id($id,$field){
    global $db;
    $sql="select $field from users where id=$id";
    $row=$db->fetch_row($sql);
    return $row[$field];
}
function get_location_info($id,$field){
    global $db;
    $sql="select $field from site_locations where id=$id";
    $row=$db->fetch_row($sql);
    return $row[$field];
}
function is_location_exist($location){
    global $db;
    $sql="select count(*) from site_locations where site_name='$location'";
    $row=$db->fetch_row($sql);
    if (!empty($row[0])){
        return $row[0]>0;
    } else return false;
}
function get_post_tag($id){
    global $db;
    $sql="select b.word from page_tags a,keywords b 
    where a.word_id=b.id and a.page_id=$id";
    //echo $sql;
    $result=$db->query($sql);
    $hasil="";
    while ($row=$db->fetch_array($result)){
        extract($row);
        $hasil.="$word ";
        //echo $word;
    }
    return $hasil;
}
function get_module_id($module){
    global $db;
    if (!empty($module)){
    $sql="select id from app_modules where module_name='$module'";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        
        return $row['id'];
    } else return "";
    }
}
function check_privileges(){
    global $app_role,$mod;
    $moduleid=  get_module_id($mod);
    $privileges=new RolePrivileges($app_role,$moduleid);
    return $privileges;
}
function get_module_title($module){
    global $db;
    if (!empty($module)){
    $sql="select title from app_modules where module_name='$module'";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        
        return $row['title'];
    } else return "";
    }
}
function app_menu_list($moduleid){
    global $db,$mod,$is_admin;
    if (!empty($moduleid)){
        if ($is_admin==1){
          $grant_admin='Y';
        } else {
            $grant_admin='N';
        }
            
    $sql="select * from app_menu_modules a,app_menus b 
        where a.app_menu_id=b.id and a.app_module_id=$moduleid and b.grant_admin='$grant_admin'
        order by caption";
    $query=$db->query($sql);
    if ($is_admin==1){
    echo "<a class=\"action_link\" href=\"?mod=panel\">Control Panel</a> ";
    }
        while($row=$db->fetch_array($query)){
            extract($row);
            echo "<a class=\"action_link\" href=\"$menu_url\" title=\"$tool_tips\">$caption</a> ";
        }
         
    }
}
function _showMenuHeader(){
global $mod,$action;
//echo $mod;
    $module_id=  get_module_id($mod);
//echo "<br> $module_id";
    echo "<div id=\"menu_header\">";
    app_menu_list($module_id);
    //echo " <a class=\"action_link\" href=\"?mod=users&file=logout\">Logout</a>";    
    echo "</div>";
}
function check_cookies_login(){
    if (isset($_COOKIE['username'])){
        if (is_user_exist($_COOKIE['username'])){
        
        $AppUser=new AppUsers();
        
        $user_id=$AppUser->loginUser($_COOKIE['username'], $_COOKIE['password']);
        
        //echo " password : ".$password_db;
        if ($user_id!=0){
            $_SESSION['user_id']=$user_id;
            $_SESSION['username']=$_COOKIE['username'];
            $_SESSION['login_status']=TRUE;
            $roles=$AppUser->getRole($user_id);
        if (is_array($roles)){
            if (in_array($roles, 1)){
                $_SESSION['is_admin']=1;
            } else $_SESSION['is_admin']=0;
        } else {
            if ($role==1){
                $_SESSION['is_admin']=1;
            } else $_SESSION['is_admin']=0;
        }
            
            //refresh_to("index.php?mod=events", "Anda dialihkan ke Halaman Event!", 2);
        } else {
            $_SESSION['login_status']=FALSE;
            echo "Password Salah";
        }
    }
    }
}
function checkReadPrivileges($module_id,$role_id){
    global $db;
    $sql="select grant_read from role_privileges where app_role_id=$role_id 
        and app_module_id=$module_id ";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        if ($row['grant_read']=='Y'){
            return TRUE;
        } else return FALSE;
    } else return FALSE;
    
}
function checkWritePrivileges($module_id,$role_id){
    global $db;
    $sql="select grant_write from role_privileges where app_role_id=$role_id 
        and app_module_id=$module_id ";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        if ($row['grant_write']=='Y'){
            return TRUE;
        } else return FALSE;
    } else return FALSE;
    
}
function checkSendPrivileges($module_id,$role_id){
    global $db;
    $sql="select grant_sent from role_privileges where app_role_id=$role_id 
        and app_module_id=$module_id ";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        if ($row['grant_sent']=='Y'){
            return TRUE;
        } else return FALSE;
    } else return FALSE;
    
}
function checkPrintPrivileges($module_id,$role_id){
    global $db;
    $sql="select grant_print from role_privileges where app_role_id=$role_id 
        and app_module_id=$module_id ";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        if ($row['grant_print']=='Y'){
            return TRUE;
        } else return FALSE;
    } else return FALSE;
    
}
function checkExportPrivileges($module_id,$role_id){
    global $db;
    $sql="select grant_export from role_privileges where app_role_id=$role_id and app_module_id=$module_id ";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        if ($row['grant_export']=='Y'){
            return TRUE;
        } else return FALSE;
    } else return FALSE;
    
}
function checkArchiveExist($eventid){
    global $db;
    $sql="select count(*) from _event_archives where event_id=$eventid";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        return $row[0]>0;
    } else return FALSE;
}
function get_preference($prefname){
    global $db;
    $sql="select pref_value from preferences where pref_name='$prefname'";
    $row=$db->fetch_row($sql);
    if (!empty($row)){
        return $row[0];
    } else return '';
}
function set_preference($prefname,$value){
    global $db;
    $sql="update preferences set pref_value='$value' 
    where pref_name='$prefname'";
    $db->query($sql); 
}
function send_mail($from,$to,$cc,$bcc,$subject,$body){
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
    $headers .= 'To: $to' . "\r\n";
    if (!empty($from)){
    $headers .= 'From: $from' . "\r\n";    
    }
    if (!empty($cc)){
    $headers .= 'Cc: $cc' . "\r\n";
    }
    if (!empty($bcc)){
    //$headers .= 'Bcc: $bcc' . "\r\n";
    }
// Mail it
    if (!mail($to, $subject, $body, $headers)){
        error_msg("Sending e-mail error!");
    }

}
function hit_posting($page_id){
    global $db;
    $sql="update _post_contents set hits=hits+1 where id=$page_id";
    $db->query($sql);
}
function create_player($movie,$title,$width,$height){
    return "<script language='javascript'>
 AC_FL_RunContent('codebase', 
    'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', 
    'width', '$width', 'height', '$height', 'src', ((!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) ? 'OSplayer' : 'OSplayer'), 
    'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'id', 
    'flvPlayer', 'allowFullScreen', 'true', 'allowScriptAccess', 'always', 
    'movie', ((!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) ? 'OSplayer' : 'OSplayer'), 
    'FlashVars', 'movie=$movie&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=$title&showTitle=yes');
</script>
<noscript>
 <object width='$width' height='$height' id='flvPlayer'>
  <param name='allowFullScreen' value='true'>
   <param name=\"allowScriptAccess\" value=\"always\"> 
  <param name='movie' value='OSplayer.swf?movie=$movie&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=$title&showTitle=yes'>
  <embed src='OSplayer.swf?movie=$movie&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=$title&showTitle=yes' 
    width='$width' height='$height' allowFullScreen='true' type='application/x-shockwave-flash' allowScriptAccess='always'>
 </object>
</noscript>";
}
function create_media_player($content_id){
    global $db,$site_url;
    if (!empty($content_id)){
        $sql="select b.filename,c.title 
        from _content_media a,_media_file b,_channel_contents c 
        where a.content_id=$content_id and a.file_id=b.id and a.content_id=c.id" ;
        //echo $sql;
        $result=$db->query($sql);
        $html="";$i=0;
        while ($row=$db->fetch_array($result)){
        if (!empty($row)){
            extract($row);
            $i++;
            $media=urldecode("media/".$filename);
            $html.="<h2>$title #$i</h2>";
            $html.=create_player($media, $title, 480, 320);
        }
        }
        return $html;
    }
}
function create_radio($key,$values,$captions,$selected){
    $html="";
    $vals=explode(';',$values);
    $caps=  explode(';', $captions);
    for($i=0;$i<count($vals);$i++){
        if ($vals[$i]==$selected){
            $html.=" <input type=\"radio\" name=\"$key\" value=\"".$vals[$i]."\" checked/>".$caps[$i];
        } else
        $html.=" <input type=\"radio\" name=\"$key\" value=\"".$vals[$i]."\"/>".$caps[$i];
    }
    return $html;
}
function create_checkbox($key,$values,$captions){
    $html="";
    $vals=explode(';',$values);
    $caps=  explode(';', $captions);
    for($i=0;$i<count($vals);$i++){
        $html.=" <input type=\"checkbox\" name=\"$key'[]'\" value=\"".$vals[$i]."\"/>".$caps[$i];
    }
    return $html;
}
?>
